package com.ziyun.erp.modules.member.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ziyun.erp.modules.member.dao.UserAdvanceDao;
import com.ziyun.erp.modules.member.entity.UserAdvanceEntity;
import com.ziyun.erp.modules.member.service.UserAdvanceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("userAdvanceService")
public class UserAdvanceServiceImpl extends ServiceImpl<UserAdvanceDao, UserAdvanceEntity> implements UserAdvanceService {
    @Autowired
    private UserAdvanceDao userAdvanceDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params, Integer memberId) {
        Page<UserAdvanceEntity> page = this.selectPage(
                new Query<UserAdvanceEntity>(params).getPage(),
                new EntityWrapper<UserAdvanceEntity>().eq("user_id", memberId).eq("disabled",0)
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils getAll(Map<String, Object> params, Integer memberId) {
        Page<UserAdvanceEntity> page = new Page<>();
        page.setCurrent(Integer.valueOf(params.get("page").toString()));
        page.setSize(Integer.valueOf(params.get("limit").toString()));
        List<UserAdvanceEntity> list = userAdvanceDao.getAll(page, memberId);
        page.setRecords(list);
        return new PageUtils(page);
    }

}
